/**
 * Created by calen on 2018/11/1.
 */
/*gis图形产品（面板，参数）*/
var gisGraphics = {
	pointResult:[],
    init: function () {
        var _this = this;
        var gisDom = $('#gisGraphics');

        /*获取gis图形产品弹出层默认值*/
        _this.gisDefaultVal();

        /*gis图形制作弹出层*/
        layLayer.open({
            title: 'gis图形制作',
            type: 1,
            area: ['650px', '550px'],
            btn: '确认',
            content: gisDom,
            yes: function (ind) {

                /*判断是否表示单日数据，并且多日数据则返回不出图*/
                if ( Global.currElementObj.isGroupByDay === 'true' && Global.postData.endTime - Global.postData.startTime > 1 ) {
                    layLayer.msg('出图请查询当日数据', {type:0, icon: 5, time: 1500});
                    return;
                }
                /*获取面板数值*/
                var gisGraphicParam = {
                    relatedField: gisDom.find('[name="relatedField"]').val(),   //关联字段
                    displayField: gisDom.find('[name="displayField"]').val(),    //展示字段
                    mainTitle: gisDom.find('[name="mainTitle"]').val(),      //主标题
                    subtitle: gisDom.find('[name="subtitle"]').val(),     //副标题
                    displayType: gisDom.find('[name="displayType"]').val(),    //展示类型
                    legendUnit: gisDom.find('[name="legendUnit"]').val(),     //图例单位
                    provinceArea: gisDom.find('[name="provinceArea"]').val(),   //省 (分类)
                    cityArea: gisDom.find('[name="cityArea"]').val(),       //市（模版）
                    productUnit: gisDom.find('[name="productUnit"]').val()     //制作单位

                };
                var areaCode = $("#addr-show02").attr("areacode");
                if(areaCode==2){

                }
                var downloadImg = $('.map-tool .download-img').show(); /*下载产品按钮*/

                switch ( gisGraphicParam.displayType ) {
                    /*散点图，使用表格数据，无需请求*/
                    case 'point' :
                        /*解析色斑图数据渲染到地图*/
                        loadLayer.pointLayer('gisPoint', gisGraphicParam.displayField);
                        /*没有下载产品功能*/
                        downloadImg.hide();
                        break;
                    /*色斑图，请求数据渲染*/
                    case 'image' :
                        _this.requestGeoLayer(gisGraphicParam);
                        break;
                    /*标签图*/
                    case 'pointImage' :
                        // loadLayer.geoPointLayer('gisPointImage', data);
                        break;
                }

                /*展示方式*/
                if ( Config.DISPLAY_TYPE === 'ONLY_MAP' ) {
                    /*弹出层（图例，标题，制作单位）*/
                    _this.gisOpenLayer(gisGraphicParam);
                }

                /*跳转到地图*/
                $('.content-nav .map-nav').trigger('click');
//        $('.content-nav .img-nav').trigger('click');
                layLayer.close(ind)
            }
        });
    },

    /*处理色斑图层*/
    requestGeoLayer: function (gisGraphicParam) {
        var _this = this;
        var loadMask = layLayer.load(0, {shade: [0.3, '#000']});

        /*获取请求数据参数*/
        _this.getGisParam(gisGraphicParam);
        /*请求色斑图数据*/
        $.ajax({
            url: Global.mdrms_service_url+'/mdrms/requestGeoByDAP',
            // url: 'http://mdrms.tunnel.qydev.com/mdrms/queryMdrmsInfo',
            //url: '../../assets/testData/geojson.json',
            type: 'post',
            //type: 'get',
            dataType: 'json',
            data: {paramStr:JSON.stringify(Global.paramObj)},
            success: function (data) {
                $('.map-tool .download-img > a').attr('href', data.imgData);
//    	  $('#img').attr('src', data.imgData+"?temp=" + Math.random());
                layLayer.close(loadMask);
                //data = JSON.parse(data.data);

                if ( !data) {
                    layLayer.msg('暂无数据', {type:0, icon: 5, time: 1500});
                    return;
                }

                /*展示方式*/
                switch ( Config.DISPLAY_TYPE ) {
                    case 'ONLY_IMAGE':
                        // var imageUrl = '../../../assets/testData/geoimg.png';
                        var imageUrl = data.imgData+"?temp=" + Math.random();
                        $('#map').html('<div class="image" style="background-image: url('+ imageUrl +')"></div>');
                        break;
                    case 'ONLY_MAP':
                        data = JSON.parse(data.data);
                        /*解析渲染色斑图*/
                        if ( !data || data.length === 0 ) {
                            layLayer.msg('暂无数据', {type:0, icon: 5, time: 1500});
                            return;
                        }
                        loadLayer.geoLayer('gisImage', data);
                        /*下载产品连接*/
                        _this.downloadImg(gisGraphicParam.mainTitle);
                        break;
                }



            },
            error: function (e) {
                console.log(e);
                layLayer.close(loadMask);
                layLayer.msg('暂无数据', {type:0, icon: 5, time: 1500});
            }
        });
    },
    /*获取gis图形产品默认值*/
    gisDefaultVal: function () {
        var gisDom = $('#gisGraphics');

        /*关联字段*/
        var relatedField = tablePage.tableHeadField.reduce(function (all, cur, ind) {
            if ( cur === '站号' ) return all;
            return all += '<option value="'+ tablePage.tableEnglishField[ind] +'">'+ cur +'</option>';
        }, '<option value="站号">站号</option>');

        /*展示字段*/
        var displayField = tablePage.tableHeadField.reduce(function (all, cur, ind) {
            if ( ['站号', '名称', '市', '时间'].indexOf(cur) > -1 ) return all;
            return all += '<option value="'+ tablePage.tableEnglishField[ind] +'">'+ cur +'</option>';
        }, '');
        gisDom.find('select[name="relatedField"]').html(relatedField);
        gisDom.find('select[name="displayField"]').html(displayField);
		//图列单位
		 $("#legendUnit").empty();
		 $("#legendUnit").append('<option value="'+ Global.colorUnit +'">'+ Global.colorUnit +'</option>');
        /*主标题*/
        var mainTitle = function(){
            /*格点特殊处理*/
            if(Global.currElementObj.isNotTable=="true"||Global.currElementObj.isNotTable==true){
                return gisDom.find('select[name="cityArea"]').val() +
                    $("#nameSelect").val() +
                    '分布图';
            }else{
                var gisprovinceArea=gisDom.find('[name="provinceArea"]').val();
                if(gisprovinceArea=="province"){
                    if(Global.layName=="农事活动气象适宜度预报" || Global.layName=="灾害监测" || Global.layName=="灾害预测"  ){
                        return  gisDom.find('select[name="cityArea"]').val() +Global.ElementName+$('#nameSelect').val()+
                            tablePage.tableHeadField[ tablePage.tableEnglishField.indexOf( gisDom.find('select[name="displayField"]').val() ) ]+'分布图';
                    }else if(Global.layName=="生育期气象适宜度预报" || Global.layName=="生育期气象适宜度评价" ){
                        return  gisDom.find('select[name="cityArea"]').val() +Global.ElementName+
                            tablePage.tableHeadField[ tablePage.tableEnglishField.indexOf( gisDom.find('select[name="displayField"]').val() ) ]+'分布图';
                    }else{
                        return $('#province_select option:selected').text() +
                            tablePage.tableHeadField[ tablePage.tableEnglishField.indexOf( gisDom.find('select[name="displayField"]').val() ) ] +
                            '分布图';
                    }

                }else if(gisprovinceArea=="city"){
                    if(Global.layName=="农事活动气象适宜度预报" || Global.layName=="灾害监测" || Global.layName=="灾害预测"  ){
                        return  $('#city_select option:selected').text() +Global.ElementName+$('#nameSelect').val()+
                            tablePage.tableHeadField[ tablePage.tableEnglishField.indexOf( gisDom.find('select[name="displayField"]').val() ) ]+'分布图';
                    }else if(Global.layName=="生育期气象适宜度预报" || Global.layName=="生育期气象适宜度评价" ){
                        return  $('#city_select option:selected').text() +Global.ElementName+
                            tablePage.tableHeadField[ tablePage.tableEnglishField.indexOf( gisDom.find('select[name="displayField"]').val() ) ]+'分布图';
                    }else{
                        return $('#city_select option:selected').text() +
                            tablePage.tableHeadField[ tablePage.tableEnglishField.indexOf( gisDom.find('select[name="displayField"]').val() ) ] +
                            '分布图';
                    }

                }else if(gisprovinceArea=="country"){
                    if(Global.layName=="农事活动气象适宜度预报" || Global.layName=="灾害监测" || Global.layName=="灾害预测"  ){
                        return $('#country_select option:selected').text() +Global.ElementName+$('#nameSelect').val()+
                            tablePage.tableHeadField[ tablePage.tableEnglishField.indexOf( gisDom.find('select[name="displayField"]').val() ) ]+'分布图';
                    }else if(Global.layName=="生育期气象适宜度预报" || Global.layName=="生育期气象适宜度评价" ){
                        return  $('#country_select option:selected').text() +Global.ElementName+
                            tablePage.tableHeadField[ tablePage.tableEnglishField.indexOf( gisDom.find('select[name="displayField"]').val() ) ]+'分布图';
                    }else{
                        return $('#country_select option:selected').text() +
                            tablePage.tableHeadField[ tablePage.tableEnglishField.indexOf( gisDom.find('select[name="displayField"]').val() ) ] +
                            '分布图';
                    }

                }else if(gisprovinceArea=="planting"){
                    return  $('#planting_select option:selected').text()+"种植区"+
                        tablePage.tableHeadField[ tablePage.tableEnglishField.indexOf( gisDom.find('select[name="displayField"]').val() ) ] +
                        '分布图';
                }
                // return gisDom.find('select[name="cityArea"]').val() +
                //     tablePage.tableHeadField[ tablePage.tableEnglishField.indexOf( gisDom.find('select[name="displayField"]').val() ) ] +
                //     '分布图';
                // }

            }

        };
        gisDom.find('input[name="mainTitle"]').val(mainTitle());

        /*副标题*/
        var subtitle = function(){
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth()+1;
            var strDate = date.getDate();
            if(month >=1 && month<=9){
                month="0"+month;
            }
            if(strDate >=0 && strDate <=9){
                strDate = "0" + strDate;
            }
            var currentdate= year + "年" + month + "月" +strDate + "日";
            return currentdate;
        }
        //gisDom.find('input[name="subtitle"]').val(subtitle());
        gisDom.find('input[name="subtitle"]').val(Global.gisTimeTitle);

        /*制图单位*/
        var productUnit = function () {
            // return gisDom.find('select[name="cityArea"]').val() + '气象局';
            var gisprovinceArea=gisDom.find('[name="provinceArea"]').val();
            if(gisprovinceArea == "planting"){//种植
                $('#planting').show();
                $('#province').hide();
                $('#city').hide();
                $('#country').hide();
                return "陕西省农业遥感与经济作物气象服务中心";
            }
            else if(gisprovinceArea == "province"){
                // return $('#province_select option:selected').text() + '气象局';
                $('#province').show();
                $('#city').hide();
                $('#country').hide();
                $('#planting').hide();
                return "陕西省农业遥感与经济作物气象服务中心";
            }else if(gisprovinceArea == "city"){
                $('#province').show();
                $('#city').show();
                $('#country').hide();
                $('#planting').hide();
                return $('#city_select option:selected').text() + '气象局';
            }else if(gisprovinceArea == "country"){
                $('#province').show();
                $('#city').show();
                $('#country').show();
                $('#planting').hide();
                return $('#country_select option:selected').text() + '气象局';
            }
        };
        gisDom.find('input[name="productUnit"]').val(productUnit());

        /*渲染方案获取*/
        gisDom.find('.render-plan').html(Global.legendColor.reduce(function (all, cur) {
            return all += '<span class="plan-item" style="background-color: '+ cur.color +';"></span>';
        }, ''));

        layForm.render(null, 'gisGraphics');

        /*改变展示列和模版选择时，同时改变主标题和制图单位*/
        layForm.on('select(displayField)', function () {
            gisDom.find('input[name="mainTitle"]').val(mainTitle());
            var nameSelectVal=$('#nameSelect option:selected').val()//显示字段值
            var displayval=gisDom.find('[name="displayField"]').val();
            if(nameSelectVal=='光温水' ||  nameSelectVal == "干旱预警"){

                colorSelect.requestDataWithCallback(nameSelectVal+'/'+displayval,function () {
                    var v=Global.legendColor;
                    var changeColor = '';
                    if(v.length>0){
                        for(var i=0;i<v.length;i++){
                            var color = v[i].color;
                            changeColor += '<span class="plan-item" style="background-color: '+ color +';"></span>';
                        }
                    }
                    Global.legendColor = v;
                    $('#gisGraphics').find('.render-plan').html(changeColor);
                })
				 $("#legendUnit").empty();
                 // colorSelect.init();色标不绑定
                $("#legend").find("div>input.layui-input").val(Global.colorUnit)

            }
        });
        layForm.on('select(cityArea)', function () {
            gisDom.find('input[name="mainTitle"]').val(mainTitle());
            gisDom.find('input[name="productUnit"]').val(productUnit());

        });
		   layForm.on('select(planting)', function () {
            gisDom.find('input[name="mainTitle"]').val(mainTitle());
            gisDom.find('input[name="productUnit"]').val(productUnit());

        });

        // layForm.on('select(provinceArea)', function () {
        //     gisDom.find('input[name="mainTitle"]').val(mainTitle());
        //     gisDom.find('input[name="productUnit"]').val(productUnit());
        //
        // });

        layForm.on('select(country)', function () {
            gisDom.find('input[name="mainTitle"]').val(mainTitle());
            gisDom.find('input[name="productUnit"]').val(productUnit());
        });

    },
    /*获取gis请求参数*/
    getGisParam: function (gisGraphicParam) {
		var _this = this;
        /*格点特殊处理*/
        if(Global.currElementObj.isNotTable=="true"||Global.currElementObj.isNotTable==true){

        }else{
            /*组织站点数据*/
            _this.pointResult=[];
			if(tablePage.pointResultData.length>0){
                for(var x=0;x<tablePage.pointResultData.length;x++){
                    var disstring=gisGraphicParam.displayField;
                    var disval=tablePage.pointResultData[x][disstring].toString();
                    if(disval.indexOf("999")=== -1){//不包含999的值
                        _this.pointResult.push(tablePage.pointResultData[x])
                    }
                }
            }
            var pointArray = _this.pointResult.map(function (cur) {
                var lon = null, lat = null, stationName = null;
                customizeStation.station.forEach(function (sta) {
                    if( cur['站号'] === sta.V01000 ){ stationName = sta.CHNAME;lon = sta.V06001; lat = sta.V05001; }
                });
                return {stationNum: cur['站号'], stationName: stationName,value: cur[gisGraphicParam.displayField], lon: lon, lat: lat};
            });
        }
        var lengendArray=[],
            extractValue = Global.legendColor.map(function (cur) {
                lengendArray.push({
                    Value: Number(cur.value),
                    Caption: cur.caption,
                    LineStyle: { color: hexToRgba(cur.color,255), Width: 1, SymbolID: 0 },
                    FillStyle: { BackColor: "RGBA(0,0,0,0)", ForeColor: hexToRgba(cur.color,255), SymbolID:0 }
                });
                return cur.value;
            }).join(' ');    //插值分段
        if(lengendArray.length>0){
            lengendArray[0].LegendItemLineStyle={color:"RGBA(192,192,192)",
                Width:1,
                SymbolID:0};
        }
        let areaName=$("#addr-show02").text();


        Global.paramObj = {
            UserID: "1540993521107",        //new Date().getTime();//用户ID DAP固定参数
            Method: "ExecuteModel",       //DAP固定参数
            Name: $('input:radio[name=legendType]:checked').eq(0).val() == "autoSection" ? gisGraphicParam.provinceArea + "_graphic_autoSection" : gisGraphicParam.provinceArea + "_graphic",
            Group: "Group",       //固定 与DAP中服务组别对应
            StartTime: "2018-10-31 08:00:00",       //时间参数 暂时没有用到
            EndTime:"2018-11-28 08:00:00",
            mainTitle: gisGraphicParam.mainTitle,       //主标题
            pointArray: pointArray,       //点数据
            subTitle: gisGraphicParam.subtitle,       //副标题
            organization: gisGraphicParam.productUnit,        //制图单位
            clipRange: "[NAME]='" + gisGraphicParam.cityArea + "'",       //图片产品裁剪范围,值为DAP出图模板数据源的列与值
            filterCondition: "[NAME]='" + gisGraphicParam.cityArea + "'",       //裁剪范围,值为DAP出图模板数据源的列与值
            idwRange: Global.idwRange,        //插值范围 根据实际项目需要配置
            extractValue: extractValue,     //插值分段
            legendArray: lengendArray ,   //图例
            shpPath:"../../GraphicProductTemplate/sx/province_china2000.shp",
			dataSet:"province_china2000"
            // ShpPath: "/web/DAP/Data/GraphicProductTemplate/sx/ShanXi_County.shp"  ,//预报 的shp路径
            //TemplatePath:"/web/DAP/Data/GraphicProductTemplate/sx/DryHotWind_template_province.xml" ,//预报的模型xml
            //AreaName:"",
            //ShpName:""
        };
        if($('input:radio[name=legendType]:checked').eq(0).val() == "autoSection"){
            Global.paramObj.contourCount=lengendArray.length;
        }

        /*开始结束时间*/
        var start=""+Global.postData.startTime;
        var end=""+Global.postData.endTime;
        var startYear=start.substring(0,4);
        var startMon=start.substring(4,6);
        var startDay=start.substring(6,8);
        var endYear=end.substring(0,4);
        var endMon=end.substring(4,6);
        var endDay=end.substring(6,8);
        Global.paramObj.StartTime=startYear+"-"+startMon+"-"+startDay+" 00:00:00";
        Global.paramObj.EndTime=endYear+"-"+endMon+"-"+endDay+" 00:00:00";

        var gisprovinceArea=gisGraphicParam.provinceArea;
        /*格点匹配对应服务名*/
        var provinceName=$('#province_select option:selected').text();
        var cityNname=$('#city_select option:selected').text();
        var countryName=$('#country_select option:selected').text()
        if(Global.currElementObj.isNotTable=="true"||Global.currElementObj.isNotTable==true){
            Global.paramObj.Name="province" + "_" + Global.currElementObj.dapServerName + "_gridGraphic";
            var nameType=$("#nameSelect").val();
            $.ajax({
                url: 'xml/menu_forcast.xml',
                type: 'get',
                dataType: 'xml',
                async: false,
                success: function (res) {
                    $(res).find("elements").map(function () {
                        var elementName= $(this).attr("name");
                        if(nameType == elementName){
                            $(this).find("TemplatePath").map(function () {
                                var cityval=$(this).attr("city");
                                //  var tempath= $(this).attr("path");
                                if(gisprovinceArea == cityval && cityval=="province"){
                                    Global.paramObj.ShpPath="/web/DAP/Data/GraphicProductTemplate/sx/ShanXi_Province.shp";
                                    Global.paramObj.TemplatePath =$(this).attr("path");
                                    Global.paramObj.AreaName="[NAME]='" + provinceName + "'";
                                    Global.paramObj.ShpName="ShanXi_Province";
                                }else if(gisprovinceArea == cityval && cityval=="city"){
                                    Global.paramObj.ShpPath="/web/DAP/Data/GraphicProductTemplate/sx/ShanXi_City.shp";
                                    Global.paramObj.TemplatePath=$(this).attr("path");
                                    Global.paramObj.AreaName="[NAME]='" + cityNname + "'";
                                    Global.paramObj.ShpName="ShanXi_City";
                                }else if(gisprovinceArea == cityval && cityval=="country"){
                                    Global.paramObj.ShpPath="/web/DAP/Data/GraphicProductTemplate/sx/ShanXi_County.shp"
                                    Global.paramObj.TemplatePath=$(this).attr("path");
                                    Global.paramObj.AreaName="[NAME]='" + countryName + "'";
                                    Global.paramObj.ShpName="ShanXi_County";
                                }
                            });
                        }
                    })
                },
                error: function (e) {
                    console.log(e);
                }
            })

        }else{//不是格点
            if(gisprovinceArea == "city"){
                //Global.paramObj.Name="city_graphic";
                Global.paramObj.Name = $('input:radio[name=legendType]:checked').eq(0).val() == "autoSection" ? "city_graphic_autoSection" : "city_graphic",
                    Global.paramObj.filterCondition="[NAME]='" + cityNname + "'";
                Global.paramObj.clipRange="[NAME]='" + cityNname + "'";
                Global.paramObj.shpPath="../../GraphicProductTemplate/sx/city_china2000.shp";
				 Global.paramObj.dataSet="city_china2000";
            }else if(gisprovinceArea == "country"){
                Global.paramObj.Name = $('input:radio[name=legendType]:checked').eq(0).val() == "autoSection" ? "country_graphic_autoSection" : "country_graphic",
                    //Global.paramObj.Name="country_graphic";
                    Global.paramObj.filterCondition="[NAME]='" + countryName + "'";
                Global.paramObj.clipRange="[NAME]='" + countryName + "'";
                Global.paramObj.shpPath="../../GraphicProductTemplate/sx/county_china2000.shp";
				  Global.paramObj.dataSet="county_china2000";
            }else if(gisprovinceArea=="planting"){
                var planName=$('#planting_select option:selected').val()+".shp";
				  var template="../../GraphicProductTemplate/sx/temp_"+$('#planting_select option:selected').val();
				   var planText=$('#planting_select option:selected').text();
                Global.paramObj.Name=$('input:radio[name=legendType]:checked').eq(0).val() == "autoSection" ?  "province_graphic_autoSection" : "province_graphic",
                Global.paramObj.shpPath="../../GraphicProductTemplate/sx/planting_"+planName;
				Global.paramObj.clipRange="";
                Global.paramObj.filterCondition="";
				Global.paramObj.dataSet="planting_"+$('#planting_select option:selected').val();
				Global.paramObj.templatePath=$('input:radio[name=legendType]:checked').eq(0).val() == "autoSection" ?  template+"_range.xml" : template+".xml";
				
            }
        }

    },
    /*gis产品生成后的弹出层，图例，标题制作单位等*/
    gisOpenLayer: function (gisGraphicParam) {

        /*色标图例*/
        var colorString = Global.legendColor.reduce(function (all, cur) {
            return all += '<li class="item">' +
                '<span style="background-color: '+ cur.color +';" class="bg"></span>' +
                '<span class="text">'+ cur.caption +'</span>' +
                '</li>';
        }, '');
        layLayer.close(Global.colorLegendLayer);
        Global.colorLegendLayer = layLayer.open({
            type: 1,
            title: '图例' + (gisGraphicParam.legendUnit ? '('+ gisGraphicParam.legendUnit +')' : ''),
            // area: '130px',
            /*位置固定在地图左下*/
            offset: ['calc(100% - '+ (85+25*Global.legendColor.length) +'px)', '31%'],
            btn: false,         //确认按钮
            shade: false,       //遮罩
            resize: false,       //可拉伸
            closeBtn: false,     //关闭按钮
            zIndex: '199501',
            content: '<div class="color-legend-layer"><ul>'+ colorString +'</ul></div>'
        });

        /*标题*/
        var gisTitle = '<h3 class="gis-title">'+ gisGraphicParam.mainTitle + '<br>' +
            gisGraphicParam.subtitle + '</h3>';

        /*制作单位*/
        var productUnit = '<p class="gis-product-unit">'+ gisGraphicParam.productUnit +'</p>';
        $('.gis-title, .gis-product-unit').remove();
        $('body').append( gisTitle + productUnit );
        /*双击编辑*/
        $('.gis-title').dblclick(function () {
            layLayer.open({
                title: '修改标题',
                type: 1,
                btn: '确定',
                content: '<div class="layui-form">' +
                '<div class="layui-form-item"> ' +
                '<label class="layui-form-label">主标题<span style="color:#f00">*</span>:</label> ' +
                ' <div class="layui-input-block"> ' +
                '<input value="'+ $(this).html().split('<br>')[0] +'" type="text" id="gisMainTitle" autocomplete="off" placeholder="请输入主标题" class="layui-input"> ' +
                '</div> ' +
                '</div>' +
                '<div class="layui-form-item"> ' +
                '<label class="layui-form-label">副标题:</label> ' +
                '<div class="layui-input-block"> ' +
                '<input value="'+ $(this).html().split('<br>')[1] +'" type="text" id="gisSubTitle" autocomplete="off" placeholder="请输入副标题" class="layui-input"> ' +
                '</div> ' +
                '</div>' +
                '</div>',
                yes: function (ind) {
                    var gisMainTitle = $('#gisMainTitle'),
                        gisSubTitle = $('#gisSubTitle');

                    if ( gisMainTitle.val().length === 0 ) {
                        gisMainTitle.addClass('layui-form-danger').focus();
                        layLayer.msg('主标题不能为空', {type:0, icon: 5, anim: 6, time: 1500});
                        return;
                    } else {
                        gisMainTitle.removeClass('layui-form-danger');
                    }

                    $('.gis-title').html(gisMainTitle.val() + '<br>' + gisSubTitle.val());

                    layLayer.close(ind);
                }
            });
        }).Drag();
        $('.gis-product-unit').dblclick(function () {
            layLayer.open({
                title: '修改制作单位',
                type: 1,
                btn: '确定',
                content: '<div class="layui-form">' +
                '<div class="layui-form-item"> ' +
                '<label class="layui-form-label">单位名<span style="color:#f00">*</span>:</label> ' +
                '<div class="layui-input-block"> ' +
                '<input value="'+ $(this).text() +'" type="text" id="gisProductUnit" autocomplete="off" placeholder="请输入制作单位" class="layui-input"> ' +
                '</div> ' +
                '</div>' +
                '</div>',
                yes: function (ind) {
                    var gisProductUnit = $('#gisProductUnit');

                    if ( gisProductUnit.val().length === 0 ) {
                        gisProductUnit.addClass('layui-form-danger').focus();
                        layLayer.msg('制作单位不能为空', {type:0, icon: 5, anim: 6, time: 1500});
                        return;
                    } else {
                        gisProductUnit.removeClass('layui-form-danger');
                    }

                    $('.gis-product-unit').html(gisProductUnit.val());

                    layLayer.close(ind);
                }
            });
        }).Drag();
        /*重置拖拽位置*/
        $(window).on('resize', function () {
            $('.gis-title').attr('style', '');
            $('.gis-product-unit').attr('style', '');
        })
    },
    /*下载产品*/
    downloadImg: function (title) {

        /*todo 这里请求图片下载地址*/

        $('.map-tool .download-img > a')//.attr('href', 'http://127.0.0.1:8080/assets/testData/geoimg.png')
            .attr('download', title)

    }

};